package one.four.two;

public class BigInt {

	private int[] a;

	public BigInt() {

	}

	public BigInt(String s) {
		
		if (s.charAt(0) == '-') {
			a = new int[s.length()-1];
			for (int i = 1; i < s.length(); i++) {
				
				a[s.length() - 1 - i] =0 - Integer.parseInt(s.charAt(i) + "");
			}
		} else {
			a = new int[s.length()];
			for (int i = 0; i < s.length(); i++) {
				a[s.length() - 1 - i] = Integer.parseInt(s.charAt(i) + "");
			}
		}
	}

	@Override
	public String toString() {
		StringBuilder s = new StringBuilder();
		boolean b = false;
		;
		for (int i = a.length - 1; i >= 0; i--) {
			if (a[i] != 0 && !b) {
				b = true;
			}
			if (b) {
				s.append(a[i]);
			}
		}
		return s.toString();
	}

	public BigInt add(BigInt another) {
		if (another != null) {
			int[] b = another.a;
			int[] r;
			int sum;
			if (a.length >= b.length) {
				r = new int[a.length + 1];
				for (int i = 0; i < a.length; i++) {
					if (i < b.length) {
						sum = a[i] + b[i] + r[i];
						if (sum > 10) {
							r[i + 1] += sum / 10;
							r[i] = sum % 10;
						} else {
							r[i] = sum;
						}
					} else {
						sum = a[i] + r[i];
						if (sum > 10) {
							r[i + 1] += sum / 10;
							r[i] = sum % 10;
						} else {
							r[i] = sum;
						}
					}
				}
			} else {
				r = new int[b.length + 1];
				for (int i = 0; i < b.length; i++) {
					if (i < a.length) {
						sum = a[i] + b[i] + r[i];
						if (sum > 10) {
							r[i + 1] += sum / 10;
							r[i] = sum % 10;
						} else {
							r[i] = sum;
						}
					} else {
						sum = b[i] + r[i];
						if (sum > 10) {
							r[i + 1] += sum / 10;
							r[i] = sum % 10;
						} else {
							r[i] = sum;
						}
					}
				}
			}
			BigInt res = new BigInt();
			res.a = r;
			return res;
		}
		return null;
	}

	public int size() {
		return a.length;
	}

	public boolean zero() {
		for (int i = 0; i < a.length; i++) {
			if (a[i] != 0)
				return false;
		}
		return true;
	}

	public static void main(String[] args) {
		BigInt a = new BigInt("120000000000");
		BigInt b = new BigInt("3450000000000");
		BigInt c = a.add(b);
		// System.out.println(b);
		System.out.println(c);
	}
}
